import { isEmpty } from '../../utils/util'

const user = {
  state: {
    token: isEmpty(sessionStorage.getItem('token')) ? '' : sessionStorage.getItem('token'),
    userObj: isEmpty(sessionStorage.getItem('userData')) ? {} : JSON.parse(sessionStorage.getItem('userData'))
  },
  mutations: {
    SET_TOKEN: (state, token) => {
      state.token = token
    },
    SET_USER_INFO: (state, userInfo) => {
      state.userObj = userInfo
    }
  },
  actions: {
    setToken({ commit }, token) {
      commit('SET_TOKEN', token)
    },
    setUserInfo({ commit }, userInfo) {
      commit('SET_USER_INFO', userInfo)
    }
  }
}

export default user
